let source;
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();

navigator.mediaDevices.getUserMedia({
  audio: {
    mandatory: {
      chromeMediaSource: 'desktop'
    }
  },
  video: {
    mandatory: {
      chromeMediaSource: 'desktop'
    }
  }
}).then(stream => {
  source = audioCtx.createMediaStreamSource(stream);
})


const initSource = () => {
  let time;
  return new Promise((resolve,reject)=>{
    time = setInterval(()=>{
      if(source){
        clearInterval(time)
        resolve({
          source, audioCtx
        })
      }
    })
  })
}

export {
  initSource
}